<?php
defined('IN_ADMIN') or exit('No permission resources.');
$show_dialog = 1;
include $this->admin_tpl('header', 'admin');
function mg_state_link($r_state, $r_id, $r_field='state')
{
	$array = array(0=>'<b style="color:red;">×</b>', 1=>'<b style="color:green">√</b>');
	$state = $r_state ? 0 : 1 ;
	$str = "<a href=\"?m={$_GET['m']}&c={$_GET['c']}&a=handle&handleid={$r_id}&field={$r_field}&state={$state}\" title=\"(点击改变状态)\">{$array[$r_state]}</a>";
	return $str;
}
?>
<style>
.high{background-color:green; width:45px; height:18px; display: block;color:#fff; text-align: right;}
.low{background-color:red; width:45px; height:18px; display: block;color:#fff; text-align: right;}
</style>
<div class="pad-lr-10">
<form name="myform" id="myform" action="" method="get" >
<input type="hidden" name="m" value="<?=$_GET['m']?>">
<input type="hidden" name="c" value="<?=$_GET['c']?>">
<input type="hidden" name="a" value="init">
<input type="hidden" name="submit" value="submit">
<input type="hidden" name="type" value="<?=$_GET['type']?>">
<input type="hidden" name="pc_hash" value="<?=$_GET['pc_hash']?>">
品牌ID:<input type='input' name="brand" id="brand" class="input-text" value="<?=isset($_GET['brand'])?$_GET['brand']:''?>">
排序方式:
<select name="sort" id="sort">
 <?=$ob_sort?>
</select>
是否免邮:
<select name="post_fee" id="post_fee">
	<option value="1">默认</option>
<option value="-1">免邮费</option>
</select>
价格:从<input type='input' name="start_price" id="start_price" class="input-text" value="<?=isset($_GET['start_price'])?$_GET['start_price']:''?>">到
<input type='input' name="end_price" id="end_price" class="input-text" value="<?=isset($_GET['end_price'])?$_GET['end_price']:''?>">
<br/>
关键字:<input type='input' name="q" id="q" class="input-text" value="<?=isset($_GET['q'])?$_GET['q']:''?>">
前台类目ID:<input type='input' name="cat" id="cat" class="input-text" value="<?=isset($_GET['cat'])?$_GET['cat']:''?>">
页数(10条/页):
<input type='input' name="start" id="start" class="input-text" value="<?=isset($_GET['start'])?$_GET['start']:1?>">
<input type='submit' name="" class="mybutton btnblue small" value="检索商品">
<input type='reset' name="" class="mybutton btnblue small" onclick="add_rules();" value="添加此规则">
</from>
<p stype="color:red;"> *共<?=$infos->total_results?>条数据,当前第<?=$infos->page?>页</p>
<div class="table-list">
<table width="100%" cellspacing="0">
	<thead>
		<tr>
			<th align="center" >商品图片</th>
			<th align="center" >店主昵称</th>
			<th align="center" width="180">本月销量</th>
			<th align="center" width="180">商品名称</th>
			<th align="center">原价<br/>现价</th>
			<th align="center" >邮费</th>
		</tr>
	</thead>
<tbody>
<?php
if(isset($infos)){
	$item_infos = $infos->item_list->tmall_search_item;
	foreach($item_infos as $info){
?>
	<tr style = "height:80px;overflow:hidden;text-overflow: ellipsis; ">
		<td align="center"><img src="<?=$info->pic_path?>" width="100" height="100"/></td>
		<td align="center"><?=$info->nick?></td>
		<td align="center"><?=$info->sold?></td>
		<td align="center"><a href="<?=$info->url?>" target="_blank"><?=$info->title?></a></td>
		<td align="center"><?=$info->price?><br/><?=$info->price_with_rate?></td>
		<td align="center"><?=$info->fast_post_fee?></td>
	</tr>
<?php
	}
}
?>
</tbody>
</table>
<?php if(isset($infos)){ ?>
<table width="48%" cellspacing="0" style="width:48%; float:left; ">
	<thead>
		<tr  colspan="2">
			<th  align="center" width="180">相关前端类目ID:</th>
		</tr>
		<tr>
			<th align="center" width="180">关键字ID(前端类目ID)</th>
			<th align="center">关键字</th>
		</tr>
	</thead>
<tbody>
<?php
	$cats_infos = $infos->cat_list->tmall_cat;
	foreach($cats_infos as $info){	?>
	<tr style = "height:80px;overflow:hidden;text-overflow: ellipsis; ">
		<td align="center"><?=$info->cat_id?></td>
		<td align="center"><?=$info->cat_name?></td>
	</tr>
<?php	} ?>

</tbody>
</table>
<?php }?>
<?php if(isset($infos)){ ?>
<table width="50%" cellspacing="0" style="width:48%; float:right; ">
	<thead>
		<tr colspan="2">
			<th  align="center" width="180">相关品牌ID:</th>
		</tr>
		<tr>
			<th align="center" width="180">关键字ID(品牌ID)</th>
			<th align="center">名称</th>
		</tr>
	</thead>
<tbody>
<?php
	$brand_infos = $infos->brand_list->tmall_brand;
	foreach($brand_infos as $info){ ?>
	<tr style = "height:80px;overflow:hidden;text-overflow: ellipsis; ">
		<td align="center"><?=$info->brand_id?></td>
		<td align="center"><?=$info->brand_name?></td>
	</tr>
<?php	} ?>

</tbody>
</table>
<?php } ?>
</div>
</div>
<script type="text/javascript">
function add_rules(){
	var mod = '<?=$_GET['type']?>';
	var brand = $('#brand').val();
	var sort = $('#sort').val();
	var start = $('#start').val();
	var post_fee = $('#post_fee').val();
	var start_price = $('#start_price').val();
	var end_price = $('#end_price').val();
	var q = $('#q').val();
	var cat = $('#cat').val();
	$.ajax({
  		type: "POST",
   		url: "?m=<?=$_GET['m']?>&c=<?=$_GET['c']?>&a=add_rules&pc_hash=<?=$_GET['pc_hash']?>",
   		data: {brand:brand,sort:sort,start:start,mod:mod,post_fee:post_fee,start_price:start_price,end_price:end_price,q:q,cat:cat},
   		success: function(res){
   			window.opener.fillcontent(res);
   			alert('添加规则成功!');
			}
		});
	}
</script>
</body>
</html>